use axum::extract::Path;
use axum::{routing::get, Json, Router};
use serde::Serialize;

// 响应结构体
#[derive(Serialize)]
struct Response {
    code: u16,
    message: String,
}

async fn hello(Path(name): Path<String>) -> Json<Response> {
    Json(Response {
        code: 200,
        message: format!("Hello, {}", name),
    })
}

#[tokio::main]
async fn main() {
    let app = Router::new().route("/hello/:name", get(hello));

    // 启动服务
    let listener = tokio::net::TcpListener::bind("127.0.0.1:18076")
        .await
        .unwrap();
    axum::serve(listener, app).await.unwrap();
}
